/**
 * JourneyView Class
 * 
 * @author Matt, Kellie, Huy
 * @version 1.0
 * 
 * This class also uses a Absolute Layout view. Checkout the StoreView
 * class to see more information about how to use absolute layouts. 
 */

package edu.gatech.cs2340.bytebankers.view;

import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import edu.gatech.cs2340.bytebankers.presenter.IJourneyPresenter;

import javax.swing.JTextField;
import javax.swing.ImageIcon;

import org.omg.CORBA.PRIVATE_MEMBER;
import org.omg.CORBA.PUBLIC_MEMBER;

public class JourneyView extends JPanel implements IJourneyView {

    private IJourneyPresenter presenter;
    private JButton btnOptions, btnKeepWalking;
    private JOptionPane options;
    private int foodLeft, day, year;
    private String month;
    private double distance;
	JPanel infopanel = new JPanel();
    JLabel distLabel;
    JLabel foodLeftLabel;
    private JLabel wagonimage, image;
    private int storedx = startx;
    private double percentageTraveled;
    private int distancebetweenlocations;

    public JourneyView(IJourneyPresenter presenter) {

	this.presenter = presenter;
	setLayout(null); //Absolute layout
	percentageTraveled = 0;

	/**
	 * Panel "infopanel" for the small information panel in the upper left
	 * corner.
	 */

	infopanel.setLayout(null);
	infopanel.setBackground(Color.DARK_GRAY);
	infopanel.setForeground(Color.DARK_GRAY);
	infopanel.setBounds(16, 16, 236, 94); // set location
	add(infopanel);

	JLabel lblDate = new JLabel("Date: ");
	lblDate.setForeground(Color.WHITE);
	lblDate.setBounds(6, 6, 204, 16); // set location
	infopanel.add(lblDate);

	JLabel lblNewLabel = new JLabel("Distance Traveled: ");
	lblNewLabel.setForeground(Color.WHITE);
	lblNewLabel.setBounds(6, 28, 204, 16); // set location
	infopanel.add(lblNewLabel);

	JLabel lblNewLabel_1 = new JLabel("Food Left:");
	lblNewLabel_1.setForeground(Color.WHITE);
	lblNewLabel_1.setBounds(6, 50, 204, 16); // set location
	infopanel.add(lblNewLabel_1);

	JLabel lblWeather = new JLabel("Weather: ");
	lblWeather.setForeground(Color.WHITE);
	lblWeather.setBounds(6, 72, 204, 16); // set location
	infopanel.add(lblWeather);

	/**
	 * Options JButton
	 * 
	 * When this button is pressed, a JOption Pane will appear with more
	 * options about the journey
	 */
	btnOptions = new JButton("Options");
	btnOptions.setBounds(301, 436, 117, 29);
	add(btnOptions);

	ActionListener optionlistener = new ButtonListener();
	btnOptions.addActionListener(optionlistener);

	JOptionPane options = new JOptionPane();
	options.setSize(550, 300);

	/**
	 * Continue JButton
	 * 
	 * When this button is pressed, the Journey will continue. All variables
	 * will be incremented.
	 */
	btnKeepWalking = new JButton("Keep Walking");
	btnKeepWalking.setBounds(421, 436, 117, 29);

	ActionListener turnlistener = new ButtonListener();
	btnKeepWalking.addActionListener(optionlistener);

	add(btnKeepWalking);

	distLabel = new JLabel();
	distLabel.setForeground(Color.WHITE);
	distLabel.setBounds(130, 29, 90, 14);

	foodLeftLabel = new JLabel();
	foodLeftLabel.setForeground(Color.WHITE);
	foodLeftLabel.setBounds(130, 55, 90, 14);
	infopanel.add(foodLeftLabel);

	infopanel.add(distLabel);

	// add the wagon image
	wagonimage = new JLabel("");

	wagonimage
		.setIcon(new ImageIcon(
			StoreBGView.class
				.getResource("/edu/gatech/cs2340/bytebankers/graphics/wagonBG.png")));

	wagonimage.setBounds(-100, 0, 860, 500);

	add(wagonimage);

	// add the background image
	image = new JLabel("");

	image.setIcon(new ImageIcon(
		StoreBGView.class
			.getResource("/edu/gatech/cs2340/bytebankers/graphics/JourneyViewBG.png")));
	
	image.setBounds(startx, 0, 3000, 500);
	add(image);

    }

    /**
     * Returns the JourneyView Panel
     * 
     * @return JourneyView panel
     */
    public JPanel getMainPanel() {
	return this;
    }

    /**
     * Private Class for Button Listeners
     */
    private class ButtonListener implements ActionListener {

	public void actionPerformed(ActionEvent event) {
	    if (event.getSource() == btnOptions)
		onOptionClick();
	    if (event.getSource() == btnKeepWalking) {
		onTurnClick();
		//repaint();
	    }
	}
	
    }
	
    /**
     * Setter for Date
     * 
     * @param int day
     * @param String
     *            month
     * @param int year
     */
    public void setDate(int day, String month, int year) {
	this.day = day;
	this.month = month;
	this.year = year;

	JLabel dateLabel = new JLabel(this.day + " " + this.month + "  ,"
		+ this.year);
	dateLabel.setForeground(Color.WHITE);
	dateLabel.setBounds(130, 7, 46, 14);
	infopanel.add(dateLabel);
    }

    /**
     * Setter for distance traveled
     * 
     * @param double distance traveled
     */
    public void setDistanceTravelled(double distanceTravelled) {
	this.distance = distanceTravelled;
	distLabel.setText(" " + distanceTravelled);

    }

    /**
     * Setter for amount of food left
     * 
     * @param int food left
     */
    public void setFoodLeft(int foodLeft) {
	this.foodLeft = foodLeft;
	foodLeftLabel.setText(foodLeft + "");

    }

    /**
     * Setter for weather. We will do this later
     */
    public void setWeather() {
	// not doing this right now
    }

    /**
     * Handles events associated with "Keep Walking" button
     */
    public void onTurnClick() {
	presenter.onTurnClick();
    }

    /**
     * Handles events associated with "Options" button
     */
    public void onOptionClick() {
	presenter.onOptionClick();
    }

    /**
     * Setter for percentage traveled
     * 
     * @param int percentage traveled
     */
    public void setPercentageTraveled(double percentagetraveled) {
	this.percentageTraveled = percentagetraveled;

    }
    
    /**
     * Getter for percentageTraveled
     */
    public double getPercentageTraveled(){
    	return percentageTraveled;
    }
	
	public JLabel getImage() {
		return image;
	}

	public void setImage(JLabel image) {
		this.image = image;
		
	}

    /**
     * Setter for distance between locations
     * 
     * @param int distance between locations
     */
    public void setDistanceBetweenLocations(int distancebetweenlocations) {
	this.distancebetweenlocations = this.distancebetweenlocations;
    }
}